package com.itheima.service.impl;

import com.itheima.common.utils.ValidateCodeUtils;
import com.itheima.service.ValidatecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ValidatecodeServiceimpl implements ValidatecodeService {
    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public void send4Oreder(String telephone) {

        String code= ValidateCodeUtils.generateValidateCode(6)+"";
        System.out.println("本次手机号"+telephone+"生成验证码："+code);
        redisTemplate.opsForValue().set(telephone + "Order",code,5, TimeUnit.MINUTES);
    }

    @Override
    public void send4Login(String telephone) {
        String code = ValidateCodeUtils.generateValidateCode(6) + "";
        System.out.println("本次手机号"+telephone+"生成验证码："+code);
        redisTemplate.opsForValue().set(telephone + "Order",code,5, TimeUnit.MINUTES);
    }
}
